package cn.labbook.bluetooth.service.impl;

import cn.labbook.bluetooth.constant.CommonConstant;
import cn.labbook.bluetooth.entity.Constant;
import cn.labbook.bluetooth.mapper.ConstantMapper;
import cn.labbook.bluetooth.service.IConstantService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lonzy
 * @since 2019-08-29
 */
@Service
public class ConstantServiceImpl extends ServiceImpl<ConstantMapper, Constant> implements IConstantService {

    private static final double PROTECT_PRICE = 50d;


    @Override
    public double getProtectPrice() {
        Constant constant = getById(Constant.Key.PROTECT_PRICE);
        if (Objects.isNull(constant)) {
            return PROTECT_PRICE;
        }
        Double value = constant.getV();
        if (Objects.isNull(value)) {
            return PROTECT_PRICE;
        }
        return value;
    }

    @Override
    public boolean timingTransferOpen() {
        Constant constant = getById(Constant.Key.TIMING_TRANSFER_SWITCH);
        if (Objects.isNull(constant)) {
            return false;
        }
        return constant.getV() != 0;
    }

    @Override
    public boolean inTimingTransferOpen() {
        Constant constant = getById(Constant.Key.IN_TIMING_TRANSFER_SWITCH);
        if (Objects.isNull(constant)) {
            return false;
        }
        return constant.getV() != 0;
    }
}
